<?php

namespace App\Http\Controllers\Home;

use Illuminate\Http\Request;
use Cache;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB;

class VoluAndLoveController extends Controller
{
    /**
     * 展示志愿者活动视图
     *
     * @return object
     */
    public function getIndex()
    {
        //查询数据
        $activities = DB::table('activities')->where('sort','1')->paginate(5);
         //获取缓存数据
        $value = Cache::get('head');

        return view('Home.loveser.index',['type'=>$value['type'],'config'=>$value['config'],'blinks'=>$value['blinks'],'datas'=>$value['datas'],'ptype'=>$value['ptype'],'pts'=>$value['pts'],'activities'=>$activities]);
    }

    /**
     * 展示志愿者活动视图
     *
     * @return object
     */
    public function getAct($id)
    {
        //查询数据库
        $activities = DB::table('activities')->where('id',$id)->first();
         //获取缓存数据
        $value = Cache::get('head');
        $v = Cache::get('pcon');
        return view('Home.loveser.act',['type'=>$value['type'],'config'=>$value['config'],'blinks'=>$value['blinks'],'datas'=>$value['datas'],'ptype'=>$value['ptype'],'pts'=>$value['pts'],'activities'=>$activities,'pcons'=>$v['pcons'],'acts'=>$v['acts']]);
    }


   /**
     * 展示志愿者手记视图
     *
     * @return object
     */
    public function getNotes()
    {
        //查询数据库
        $notes = DB::table('activities')->where('sort','0')->where('status','1')->paginate(5);
         //获取缓存数据
        $value = Cache::get('head');

        return view('Home.loveser.notes',['type'=>$value['type'],'config'=>$value['config'],'blinks'=>$value['blinks'],'datas'=>$value['datas'],'ptype'=>$value['ptype'],'pts'=>$value['pts'],'notes'=>$notes]);
    }

    /**
     * 展示志愿者手记视图
     *
     * @return object
     */
    public function getInfo($id)
    {
        //查询数据库
        $notes = DB::table('activities')->where('id',$id)->first();
         //获取缓存数据
        $value = Cache::get('head');
        $v = Cache::get('pcon');
        return view('Home.loveser.info',['type'=>$value['type'],'config'=>$value['config'],'blinks'=>$value['blinks'],'datas'=>$value['datas'],'ptype'=>$value['ptype'],'pts'=>$value['pts'],'notes'=>$notes,'pcons'=>$v['pcons'],'acts'=>$v['acts']]);
    }
    /*
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function getIndex()
    {
        //获取全部以及分类
        $type = DB::table('type')->where('pid',0)->get();

        //获取配置信息
        $config = DB::table('config')->first();

        //友情链接
        $blinks = DB::table('blink')->get();

        //遍历下部的栏目
        $datas = self::pushCates(self::pushType(),0);


         return view('Home.loveser.index',['type'=>$type,'config'=>$config,'blinks'=>$blinks,'datas'=>$datas]);
    }


     //获取全部一级分类板块
    public static function pushType()
    {
        return $cates = DB::table('type')->get();


    }

    
    //获取二级分类
    public  static function pushCates($cates,$pid)
    {
        $data = [];
        foreach($cates as $k=>$v)
        {
            if($v->pid == $pid){

               $v->sub = self::pushCates($cates,$v->id);
               $data[] = $v;
            }
        }
        return $data;
    }

   //志愿者活动
    public function getShow()
    {

    }

   
}
